home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C19 / stringConv.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  561 b   |  27 lines

  1. //: C19:stringConv.h
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Chuck Allison's string converter
  7. #ifndef STRINGCONV_H
  8. #define STRINGCONV_H
  9. #include <string>
  10. #include <sstream>
  11.  
  12. template<typename T>
  13. T fromString(const std::string& s) {
  14.   std::istringstream is(s);
  15.   T t;
  16.   is >> t;
  17.   return t;
  18. }
  19.  
  20. template<typename T>
  21. std::string toString(const T& t) {
  22.   std::ostringstream s;
  23.   s << t;
  24.   return s.str();
  25. }
  26. #endif // STRINGCONV_H ///:~
  27.